package com.wl.spring.biz;

import com.wl.spring.jdbc.entity.Account;
import com.wl.spring.jdbc.entity.Oprecored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

public class BankBiz {

    @Autowired
    Account aDao;
    @Autowired
    Oprecored oDao;

    @Transactional(rollbackFor = BizException.class,
                    //  rollbackFor => 编译器异常
                    //  noRollbackFor => 运行时异常
                    noRollbackFor = ArithmeticException.class)
    //存款
    public void deposit(long id, double money) {
        Oprecored oprecored = new Oprecored();
        oprecored.setAid(id);
        oprecored.setOpmoney(money);
        oDao.insert(oprecored);

        if(money >5000){
            //编译时异常
            throw new BizException("存款金额大于5000");
        }
//        int i = 1/0;     运行时异常
        aDao.updateBalanceById(id,money);

    }

    //取款
    public void withdraw(long id, double money) {

    }

    //转账
    public void transfer(long id1, double money){

    }
}
